package lar.system.opengl;

import java.util.Collections;
import java.util.Vector;

import javax.microedition.khronos.opengles.GL11;

public class GLColor 
{
	public static final GLColor RED = new GLColor("RED",1f,0f,0f,1f);
	public static final GLColor GREEN = new GLColor("GREEN",0f,1f,0f,1f);
	public static final GLColor BLUE = new GLColor("BLUE",0f,0f,1f,1f);
	public static final GLColor BLACK = new GLColor("BLACK",0.2f,0.2f,0.2f,1f);
	public static final GLColor WHITE = new GLColor("WHITE",1f,1f,1f,1f);
	public static final GLColor ORANGE = new GLColor("ORANGE",1f,0.5f,0f,1f);
	public static final GLColor PURPLE = new GLColor("PURPLE",0.5f,0f,0.5f,1f);
	public static final GLColor YELLOW = new GLColor("YELLOW",1f,1f,0f,1f);
	public static final GLColor TEAL = new GLColor("TEAL",0.21f,0.45f,0.53f,1f);
	public static final GLColor GREY = new GLColor("GREY",0.5f,0.5f,0.5f,1f);
	public static final GLColor PINK = new GLColor("PINK",1f,0.65f,0.69f,1f);
	public static final GLColor BROWN = new GLColor("BROWN",0.58f,0.29f,0f,1f);
	public static final GLColor LIME = new GLColor("LIME",0.7f,1f,0f,1f);
	public static final GLColor DARKRED = new GLColor("DARKRED",0.5f,0f,0f,1f);
	public static final GLColor DARKGREEN = new GLColor("DARKGREEN",0f,0.5f,0f,1f);
	public static final GLColor DARKNOOB = new GLColor("DARKNOOB",0.5f,0.5f,0f,1f);
	
	public static final Vector<GLColor> ALL;
	public static final Vector<GLColor> ALL2;
	static
	{
		ALL = new Vector<GLColor>();
		ALL.add(RED);ALL.add(GREEN);
		ALL.add(BLUE);ALL.add(BLACK);
		ALL.add(WHITE);ALL.add(ORANGE);
		ALL.add(PURPLE);ALL.add(YELLOW);
		ALL.add(TEAL);ALL.add(GREY);
		ALL.add(PINK);ALL.add(BROWN);
		ALL.add(LIME);ALL.add(DARKRED);
		ALL.add(DARKGREEN);ALL.add(DARKNOOB);
		//ALL.add(object);ALL.add(object);
		ALL2 = new Vector<GLColor>(ALL);
		Collections.shuffle(ALL);
	}
	
	private final float[] color;
	private String name="UNKNOWN_COLOR";
	public GLColor(float r, float g, float b, float a)
	{
		color = new float[]{r,g,b,a};
	}
	public GLColor(String name, float r, float g, float b, float a)
	{
		this.name = name;
		color = new float[]{r,g,b,a};
	}
	public GLColor(float[] color4f)
	{
		color = new float[]{color4f[0], color4f[1], color4f[2], color4f[3]};
	}
	public GLColor(String name, float[] color4f)
	{
		this.name = name;
		color = new float[]{color4f[0], color4f[1], color4f[2], color4f[3]};
	}
	public float[] asFloatArray() 
	{
		return new float[]{color[0], color[1], color[2], color[3]};
	}
	public String getName()
	{
		return name;
	}
	public void apply(GL11 gl)
	{
		gl.glColor4f(color[0], color[1], color[2], color[3]);
	}
	public void restore(GL11 gl)
	{
		gl.glColor4f(1f, 1f, 1f, 1f);
	}
	public static GLColor getByName(String name)
	{
		for(GLColor c : ALL) if(c.getName().equals(name)) return c;
		return null;
	}
	
	@Override
	public boolean equals(Object other)
	{
		if(!(other instanceof GLColor)) return false;
		GLColor other_c = (GLColor) other;
		return 
				(other_c.color[0] == color[0]) &&
				(other_c.color[1] == color[1]) &&
				(other_c.color[2] == color[2]) &&
				(other_c.color[3] == color[3]);
	}
}
